﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tilver.Coder.Core;

namespace Tilver.Coder.Win.Views
{

    public partial class ColumnView : UserControl
    {
        private IList _dataObjects = null;
        public IList DataObjects
        {
            get { return _dataObjects; }
            set
            {
                _dataObjects = value;
                LoadColumns();
            }
        }
        public ColumnView()
        {
            InitializeComponent();
        }

        private void LoadColumns()
        {
            if (_dataObjects == null) return;
            lvColumn.Clear();
            lvColumn.Columns.Add("名称", 100);
            lvColumn.Columns.Add("类型", 100);
            lvColumn.Columns.Add("大小", 100);
            lvColumn.Columns.Add("描述", 350);
            foreach (CoderDataObject dataObject in _dataObjects)
            {
                var item = new ListViewItem(new string[]
                    {
                        dataObject.Name,
                        dataObject.DbType.ToString("g"),
                        dataObject.Size.ToString(CultureInfo.InvariantCulture),
                        dataObject.Description
                    });
                item.Tag = dataObject;
                lvColumn.Items.Add(item);
            }

        }
    }
}
